#include <stdio.h>
#include <string.h>

#define MAX_EMPLOYEES 100

typedef struct {
    int id;
    char name[20];
    float base_salary;	// 基本工资
    float bonus;		// 奖金
    float deduction;	// 扣款
    float final_salary;	// 最终工资
} Employee_t;

// 函数声明
void inputEmployees(Employee_t *emps, int *n);
void calculateFinalSalary(Employee_t *emps, int n);
void sortEmployees(Employee_t *emps, int n);
void printTopEmployee(Employee_t *emps);

int main() {
    Employee_t employees[MAX_EMPLOYEES];
    int n = 0;

    inputEmployees(employees, &n);
    calculateFinalSalary(employees, n);
    sortEmployees(employees, n);
    printTopEmployee(employees);

    return 0;
}

// 输入员工信息
void inputEmployees(Employee_t *emps, int *n) {
    printf("请输入员工数量（不超过%d）：", MAX_EMPLOYEES);
    scanf("%d", n);

    for (int i = 0; i < *n; i++) {
        printf("\n请输入第 %d 个员工的信息：\n", i + 1);
        printf("工号：");
        scanf("%d", &emps[i].id);
        printf("姓名：");
        scanf("%s", emps[i].name);
        printf("基本工资：");
        scanf("%f", &emps[i].base_salary);
        printf("奖金：");
        scanf("%f", &emps[i].bonus);
        printf("扣款：");
        scanf("%f", &emps[i].deduction);
    }
}

// 计算实发工资
void calculateFinalSalary(Employee_t *emps, int n) {
    for (int i = 0; i < n; i++) {
        emps[i].final_salary = emps[i].base_salary + emps[i].bonus - emps[i].deduction;
    }
}

// 按实发工资排序（降序）
void sortEmployees(Employee_t *emps, int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (emps[j].final_salary < emps[j + 1].final_salary) {
                Employee_t temp = emps[j];
                emps[j] = emps[j + 1];
                emps[j + 1] = temp;
            }
        }
    }
}

// 输出最高实发工资的员工信息
void printTopEmployee(Employee_t *emps) {
    printf("\n实发工资最高的员工信息如下：\n");
    printf("工号：%d\n", emps[0].id);
    printf("姓名：%s\n", emps[0].name);
    printf("基本工资：%.2f\n", emps[0].base_salary);
    printf("奖金：%.2f\n", emps[0].bonus);
    printf("扣款：%.2f\n", emps[0].deduction);
    printf("实发工资：%.2f\n", emps[0].final_salary);
}
